package cn.wolfcode.crm.service.impl;


import cn.wolfcode.crm.domain.ChangeClientLog;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.ChangeClientLogMapper;
import cn.wolfcode.crm.mapper.EmployeeMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IChangeClientLogService;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author		12900
 * @time		2018年6月19日下午12:49:54
 * @email		12900qq.com
 * @description 
 */
@Service
public class ChangeClientLogServiceImpl implements IChangeClientLogService {
	@Autowired
	private ChangeClientLogMapper mapper;

	@Autowired
	private EmployeeMapper employeeMapper;

	@Override

	public void save(ChangeClientLog entity) {
        //获取当前用户信息
        Employee user = (Employee) SecurityUtils.getSubject().getPrincipal();

        //给操作人设值
        entity.setHandleUser(user);
        //操作时间
        entity.setChangeDate(new Date());

		mapper.insert(entity);

	}

	@Override
	public List<ChangeClientLog> list() {
		return mapper.selectAll();
	}

	@Override
	public PageResult query(QueryObject qo) {
		int total = mapper.queryForCount(qo);
		if (total == 0) {
			return new PageResult();
		}
		List<ChangeClientLog> list = mapper.queryForList(qo);
		return new PageResult(total, list);
	}
}
